/*
 * @Author: xuwejie 1529315455@qq.com
 * @Date: 2023-11-04 10:30:29
 * @LastEditors: xuwejie 1529315455@qq.com
 * @LastEditTime: 2023-11-04 11:45:24
 * @FilePath: \school-shop-vue\mixins\judgment.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { $https } from "@/static/js/request.js";
export const mixins = {
  data() {
    return {

    }
  },
  filters: {
    timeFilter: function (value) {
      if (!value) return "暂无";
      return value.slice(0, 5);
    },
    spuChange(item) {
      let list = item.map((item) => Number(item.market_price)).sort();
      if (list.length == 1) {
        return list[0];
      } else {
        return list[0] + "~" + list.at(-1);
      }
    },
  },
  methods: {
    // 判断当前选择的商家是否审核成功
    determine(row) {
      let getUserInfo = this.getUserInfo();
      // uni.switchTab({
      //   url: "/pages/shop/index",
      // });
      Promise.all([getUserInfo]).then((res) => {
        this.$store.commit("changeCompanyInfo", row);
        sessionStorage.setItem("changeCompanyInfo", JSON.stringify(row));
        uni.switchTab({
          url: "/pages/shop/index",
        });
        return 
        // res[0] = 2
        // type状态为1时代表待审核,状态为2时代表审核成功
        if (res[0] == 2) {
        } else if (res[0] == 1 || res[0] == 3) {
          uni.showModal({
            title: "提示",
            content: "该账号审核未通过,请联系审核人员进行审核!",
            success: function (res) {
              if (res.confirm && res[0] == 3) {
                uni.navigateTo({
                  url: "/pages/user/qualifications",
                });
              } else if (res.cancel) {
                console.log("用户点击取消");
              }
            },
          });
        } else if (res[0] == 0) {
          uni.showModal({
            title: "提示",
            content: "该账号审核未提交资质审核,请前往资质上传",
            success: function (res) {
              if (res.confirm) {
                uni.navigateTo({
                  url: "/pages/user/qualifications",
                });
              } else if (res.cancel) {
                console.log("用户点击取消");
              }
            },
          });
        }
      });
    },
    // 获取当前用户是否审核通过
    getUserInfo() {
      return new Promise((resolve, reject) => {
        $https("GETN", "getUserInfo", {}, (res) => {
          if (res.data.errcode == 0) {
            let type = res.data.data.type;
            resolve(type);
          } else {
            reject(res.data.errmsg);
            uni.showToast({
              icon: "none",
              title: res.data.errmsg,
            });
          }
        });
      });
    },
    // 打电话
    call(phone) {
      uni.makePhoneCall({
        phoneNumber: phone, //仅为示例
      });
    },


    getShopInfo(page = 1, company_id, val) {
      return new Promise((resolve, reject) => {
        let data = {
          page: page,
          size: 20,
          company_id: company_id,
          name: val
        };
        $https("GETN", "goodsSearch", data, (res) => {
          if (res.data.errcode == 0) {
            // if (page == 1) this.shop_goods_list = [];
            // res.data.data.list.forEach((item) => {
            //   this.shop_goods_list.push(item);
            // });
            this.count = res.data.data.count;

            resolve(res.data.data.goods_list)
          } else {
            // uni.showToast({
            //   icon: "none",
            //   title: res.data.errmsg,
            // });
            reject(res.data.errmsg)
          }
        });
      })

    },
  }
}